package com.ruoyi.game.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.game.domain.RechargeCard;
import com.ruoyi.game.service.IRechargeCardService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 充值卡Controller
 *
 * @author 小胖
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/card")
public class RechargeCardController extends BaseController
{
    @Autowired
    private IRechargeCardService rechargeCardService;

    /**
     * 查询充值卡列表
     */
    @RequiresPermissions("game:card:list")
    @GetMapping("/list")
    public TableDataInfo list(RechargeCard rechargeCard)
    {
        startPage();
        List<RechargeCard> list = rechargeCardService.selectRechargeCardList(rechargeCard);
        return getDataTable(list);
    }

    /**
     * 导出充值卡列表
     */
    @RequiresPermissions("game:card:export")
    @Log(title = "充值卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RechargeCard rechargeCard)
    {
        List<RechargeCard> list = rechargeCardService.selectRechargeCardList(rechargeCard);
        ExcelUtil<RechargeCard> util = new ExcelUtil<RechargeCard>(RechargeCard.class);
        util.exportExcel(response, list, "充值卡数据");
    }

    /**
     * 获取充值卡详细信息
     */
    @RequiresPermissions("game:card:query")
    @GetMapping(value = "/{rechargeCardId}")
    public AjaxResult getInfo(@PathVariable("rechargeCardId") Long rechargeCardId)
    {
        return AjaxResult.success(rechargeCardService.selectRechargeCardByRechargeCardId(rechargeCardId));
    }

    /**
     * 新增充值卡
     */
    @RequiresPermissions("game:card:add")
    @Log(title = "充值卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RechargeCard rechargeCard)
    {
        return toAjax(rechargeCardService.insertRechargeCard(rechargeCard));
    }

    /**
     * 修改充值卡
     */
    @RequiresPermissions("game:card:edit")
    @Log(title = "充值卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RechargeCard rechargeCard)
    {
        return toAjax(rechargeCardService.updateRechargeCard(rechargeCard));
    }

    /**
     * 删除充值卡
     */
    @RequiresPermissions("game:card:remove")
    @Log(title = "充值卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rechargeCardIds}")
    public AjaxResult remove(@PathVariable Long[] rechargeCardIds)
    {
        return toAjax(rechargeCardService.deleteRechargeCardByRechargeCardIds(rechargeCardIds));
    }

    /**
     * 充值卡充值
     *
     * @param rechargeCard  充值卡
     * @return  结果
     */
    @Log(title = "充值卡", businessType = BusinessType.UPDATE)
    @PostMapping("/recharge")
    public AjaxResult recharge(@RequestBody RechargeCard rechargeCard)
    {
        return toAjax(rechargeCardService.recharge(rechargeCard));
    }
}
